package auth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zbs
 * @date 2020/10/26
 */
@RestController
public class AuthController {
    @Autowired
    TokenStore redisTokenStore;
    @RequestMapping(value = "/del")
    public void del(@RequestParam("access_token") String token){
        System.out.println("token:"+token);
        OAuth2AccessToken accessToken = redisTokenStore.readAccessToken(token);
        if(accessToken != null){
            OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
            redisTokenStore.removeAccessToken(accessToken);
            redisTokenStore.removeRefreshToken(refreshToken);
        }
    }
    @RequestMapping("/server")
    public String server(AuthorizationServerEndpointsConfigurer endpoints){
        System.out.println(endpoints.toString());
        return "这是授权服务器，auth-server";
    }
}
